/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.sistemas.sse.entity;

import java.io.Serializable;
import java.util.List;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.Proxy;

/**
 *
 * @author laptop-w8
 */
@Entity
@Table(name = "TPROV")
@Proxy(lazy = false)
public class UbigeoProvincia implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "CPROV")
    private long idProvincia;
    @Column(name = "DCOD_PROV")
    private String dCodigo;
    @Column(name = "DNM_PROV")
    private String dNombre;
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "CDEP", referencedColumnName = "CDEP", nullable = false)
    private UbigeoDepartamento departamento;
    @OneToMany(cascade = CascadeType.PERSIST, fetch =  FetchType.EAGER, mappedBy = "provincia")    
    private Set<UbigeoDistrito> distritos;

    public long getIdProvincia() {
        return idProvincia;
    }

    public void setIdProvincia(long idProvincia) {
        this.idProvincia = idProvincia;
    }

    public String getdCodigo() {
        return dCodigo;
    }

    public void setdCodigo(String dCodigo) {
        this.dCodigo = dCodigo;
    }

    public String getdNombre() {
        return dNombre;
    }

    public void setdNombre(String dNombre) {
        this.dNombre = dNombre;
    }

    public UbigeoDepartamento getDepartamento() {
        return departamento;
    }

    public void setDepartamento(UbigeoDepartamento departamento) {
        this.departamento = departamento;
    }

    public Set<UbigeoDistrito> getDistritos() {
        return distritos;
    }

    public void setDistritos(Set<UbigeoDistrito> distritos) {
        this.distritos = distritos;
    }

    public String toString(){
        return "id: "+this.dCodigo+" , nombre: "+this.dNombre;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof UbigeoProvincia) {
            UbigeoProvincia up = (UbigeoProvincia) obj;
            return up.getdCodigo().equals(this.dCodigo);
        }
        return false;
    }

}
